package com.ruoyi.web.controller.yf;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.yf.domain.YfContract;
import com.ruoyi.yf.service.IYfContractService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合同签约时间期限Controller
 * 
 * @author XiaoYi...
 * @date 2020-03-17
 * 224b4382-34eb-4ad8-90bc-3c0f6f0112ba
 */
@Controller
@RequestMapping("/yf/contract")
public class YfContractController extends BaseController
{
    private String prefix = "yf/contract";

    @Autowired
    private IYfContractService yfContractService;

    @RequiresPermissions("yf:contract:view")
    @GetMapping()
    public String contract()
    {
        return prefix + "/contract";
    }

    /**
     * 查询合同签约时间期限列表
     * 53369ff1-1dde-4d0d-a25f-d7e340ca14b0
     */
    @RequiresPermissions("yf:contract:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YfContract yfContract)
    {
        startPage();
        List<YfContract> list = yfContractService.selectYfContractList(yfContract);
        return getDataTable(list);
    }

    /**
     * 导出合同签约时间期限列表
     * b5e8dd1b-d3b5-4d9d-b3a5-511f8b37df64
     */
    @RequiresPermissions("yf:contract:export")
    @Log(title = "合同签约时间期限", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YfContract yfContract)
    {
        List<YfContract> list = yfContractService.selectYfContractList(yfContract);
        ExcelUtil<YfContract> util = new ExcelUtil<YfContract>(YfContract.class);
        return util.exportExcel(list, "contract");
    }

    /**
     * 新增合同签约时间期限
     * 28123b04-55b6-412c-aa64-c92c804ef5dd
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合同签约时间期限
     * 5124aa01-e364-4257-8013-34305fc447af
     */
    @RequiresPermissions("yf:contract:add")
    @Log(title = "合同签约时间期限", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YfContract yfContract)
    {
        return toAjax(yfContractService.insertYfContract(yfContract));
    }

    /**
     * 修改合同签约时间期限
     * 60c0aee7-948a-4d6f-aab7-7e51c9e80312
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        YfContract yfContract = yfContractService.selectYfContractById(id);
        mmap.put("yfContract", yfContract);
        return prefix + "/edit";
    }

    /**
     * 修改保存合同签约时间期限
     * b44953b9-b016-493c-a11e-b4e052f07b7a
     */
    @RequiresPermissions("yf:contract:edit")
    @Log(title = "合同签约时间期限", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YfContract yfContract)
    {
        return toAjax(yfContractService.updateYfContract(yfContract));
    }

    /**
     * 删除合同签约时间期限
     * 298ae3ef-a212-4908-9e91-592af90c6c4d
     */
    @RequiresPermissions("yf:contract:remove")
    @Log(title = "合同签约时间期限", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(yfContractService.deleteYfContractByIds(ids));
    }
}
